package com.fenqing.leetcode.code.sword_refers_offer_i;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;


/**
 * @author fenqing
 */
public class Topic58 extends Topic {

    @Execute
    public String reverseWords(String s) {
        String[] words = s.split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = words.length - 1; i >= 0; i--) {
            if (words[i].length() > 0) {
                sb.append(words[i]);
                sb.append(" ");
            }
        }
        return sb.toString().trim();
    }

    public static void main(String[] args) {
        String result = new Topic58().run("a good example");
        System.out.println(result);
    }
}
